﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;

namespace UI
{
    public partial class UrlViewer : PhoneApplicationPage
    {
        private bool stopingNavigation;

        public UrlViewer()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            stopingNavigation = false;
            this.webBrowser.Navigate(new Uri(this.NavigationContext.QueryString["url"]));
        }

        private void webBrowser_Navigating(object sender, NavigatingEventArgs e)
        {
            if (stopingNavigation == false)
            {
                this.loadingIndicator.Begin();
            }
        }

        private void webBrowser_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            if (stopingNavigation == false)
            {
                this.loadingIndicator.Stop();
            }
        }

        private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
        {
            if (stopingNavigation == false)
            {
                this.loadingIndicator.Stop();
            }
        }

        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            stopingNavigation = true;
            this.webBrowser.NavigateToString(string.Empty);
            this.loadingIndicator.Stop();
        }
    }
}